package com.card.hwatt.assembler;

import java.util.ArrayList;
import java.util.List;

import com.card.hwatt.core.ObjectUtil;
import com.card.hwatt.dto.PageResult;
import com.card.hwatt.entity.*;

/**
 * 特殊考勤
 * @author Administrator
 *
 */
public final class SpecialAssembler {

	public static PageResult<com.card.hwatt.dto.Special> convert(
			PageResult<Special> list) {
		PageResult<com.card.hwatt.dto.Special> result = new PageResult<com.card.hwatt.dto.Special>();
		result.total = list.total;
		result.rows = new ArrayList<com.card.hwatt.dto.Special>();
		for (Special item : list.rows) {
			com.card.hwatt.dto.Special dto = convert(item);
			result.rows.add(dto);
		}
		return result;
	}

	public static List<com.card.hwatt.dto.Special> convert(List<Special> list) {
		List<com.card.hwatt.dto.Special> rows = new ArrayList<com.card.hwatt.dto.Special>();
		for (Special item : list) {
			com.card.hwatt.dto.Special dto = convert(item);
			rows.add(dto);
		}
		return rows;
	}

	public static com.card.hwatt.dto.Special convert(Special entity) {
		com.card.hwatt.dto.Special dto = new com.card.hwatt.dto.Special();
		ObjectUtil.fieldCopy(entity, dto);

		dto.cardId = entity.card.id;
		dto.cardDate = entity.card.date;
		dto.employeeId = entity.card.employee.id;
		dto.employeeCode = entity.card.employee.employeeCode;
		dto.employeeName = entity.card.employee.name;
		dto.departmentName = entity.card.employee.department.name;
		return dto;
	}

	public static Special convert(com.card.hwatt.dto.Special dto) {
		Special entity = new Special();
		ObjectUtil.fieldCopy(dto, entity);

		entity.card = new Card();
		entity.card.special = entity;
		entity.card.id = dto.cardId;
		entity.card.date = dto.cardDate;

		entity.card.employee = new Employee();
		entity.card.employee.id = dto.employeeId;

		return entity;
	}
}
